package com.sgb.kjwl.view.ui.activity.self.order;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.fondesa.recyclerviewdivider.DividerDecoration;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityRequireInfoBinding;
import com.sgb.kjwl.di.transport.DaggerTransportComponent;
import com.sgb.kjwl.di.transport.TransportModule;
import com.sgb.kjwl.model.entity.self.GoodsSourceDetail;
import com.sgb.kjwl.model.entity.transport.SingleItemEntity;
import com.sgb.kjwl.model.entity.transport.TransportOrderEntity;
import com.sgb.kjwl.view.constant.RouterKey;
import com.sgb.kjwl.view.ui.activity.transport.PayGoodsOrderActivity;
import com.sgb.kjwl.view.ui.adapter.transport.CargoCustomValueAdapter;
import com.sgb.kjwl.view.ui.adapter.transport.OrderGoodsInfoAdapter;
import com.sgb.kjwl.view.ui.adapter.transport.PayGoodsInfoAdapter;
import com.sgb.kjwl.viewmodel.transport.RequireInfoViewModel;
import com.swgk.core.base.di.AppComponent;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * @author: 王彬臣
 * @date: 2021/3/10
 * @Description: 订单-货运要求和责任约定页
 */
public class OrderRequireInfoActivity extends AppActivity {
    ActivityRequireInfoBinding mBinding;
    private TransportOrderEntity goodsSourceDetail;
    private List<SingleItemEntity> mGoodsList;
    private OrderGoodsInfoAdapter mGoodsAdapter;
    private boolean isOwner;
    @Inject
    RequireInfoViewModel mViewModel;
    private String orderStatus;

    public static void start(Context context, TransportOrderEntity orderEntity, boolean isOwner) {
        Intent intent = new Intent(context, OrderRequireInfoActivity.class);
        intent.putExtra(RouterKey.STRING, orderEntity);
        intent.putExtra(RouterKey.BOOLEAN, isOwner);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerTransportComponent.builder()
                .appComponent(appComponent)
                .transportModule(new TransportModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_require_info);
        mBinding.setLifecycleOwner(this);
        mBinding.includeTitle.titleView.setText("货运要求和责任约定");
        mBinding.includeTitle.ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        initRecycler();
    }

    private void initRecycler() {
        goodsSourceDetail = (TransportOrderEntity) getIntent().getParcelableExtra(RouterKey.STRING);
        isOwner = getIntent().getBooleanExtra(RouterKey.BOOLEAN, true);
        //货源信息
        mGoodsList = new ArrayList<>();
        if (goodsSourceDetail != null && goodsSourceDetail.getStatus() != null) {
            orderStatus = goodsSourceDetail.getStatus() + "";
            mViewModel.syncGoodsInfo(mGoodsList, goodsSourceDetail, orderStatus, isOwner);
        }

        mGoodsAdapter = new OrderGoodsInfoAdapter(mGoodsList, false);
        mBinding.rvInfo.setLayoutManager(new LinearLayoutManager(this));
        mGoodsAdapter.bindToRecyclerView(mBinding.rvInfo);

    }
}
